/*
 * ijie.com main site js v1.0.0
 * by easy ()
 * Creation date: 2010/10/2
 * Modified date: 2010/10/13
 */


$.fn.extend({

    TopRolling: function () {
        var t = n = count = 0;
        //分析容器中存在的图片个数

        var outNode = $(this);
        var picNum = outNode.find(".slor .promotion").size();
        //按照图片个数生成相应按钮
        var imageButton = "<ul class='imagesList'>";
        for (var i = 0; i < picNum; i++) {
            //outNode.find(".slor a").eq(i).append('<img src="' + outNode.find(".slor a").eq(i).attr("imgsrc") + '" />');
            imageButton = imageButton + "<li class='imagesNum'  mynum='" + i + "'>●</li>";
        }
        imageButton = imageButton + "</ul>"
        $(this).prepend(imageButton);



        //设置点击切换
        outNode.find(".imagesNum").click(function () {
            var i = $(this).attr('mynum');
            outNode.find(".imagesTitle li a").css({ color: "#333333" });
            outNode.find(".imagesTitle li a").eq(i).css({ color: "#4488BB" });
            n = i;
            if (i >= picNum) return;
            //outNode.find(".slor a").filter(":visible").hide().parent().children().eq(i).show();
            //outNode.find(".slor a").filter(":visible").fadeOut("200").parent().children().eq(i).fadeIn("300");
            outNode.find(".slor .promotion").filter(":visible").fadeOut(200, function () { $(this).parent().children().eq(i).fadeIn(300); });
            //如果出现全部为隐藏的情况
            if (outNode.find(".slor .promotion").filter(":visible").size() == 0) {
                outNode.find(".slor .promotion").eq(i).fadeIn(300);
            }

            outNode.find(".imagesNum").removeClass("currently");
            $(this).addClass("currently");
        });
        //设置每一列标题栏的高度 imagesTitle
        var imagesTitleHeight = (outNode.find(".imagesTitle").height() - (picNum - 1) * 3) / picNum;
        //解决IE下高度减小的BUG
        if ($.browser.msie) {
            imagesTitleHeight = imagesTitleHeight + 1;
        }
        var imagesTitleHeight = imagesTitleHeight + "px";
        outNode.find(".imagesTitle li").css({ "line-height": imagesTitleHeight, "height": imagesTitleHeight });
        //outNode.find(".imagesTitle li a").css({ "height": imagesTitleHeight });
        //设置初始化属性
        $(this + ".slor .promotion:not(:first-child)").hide();
        $(this + ".imagesNum:first-child").addClass("currently");
        outNode.find(".imagesNum").eq(0).trigger('click');

        auto = setInterval(showAuto, 3000);
        outNode.hover(function () { clearInterval(auto) }, function () { auto = setInterval(showAuto, 3000); });
        function showAuto() {
            n = n >= (picNum - 1) ? 0 : ++n;
            outNode.find(".imagesNum").eq(n).trigger('click');

        }


        //绑定TITLE鼠标,延迟2秒执行

        setTimeout(bindTitleMouse, 2000);

        function bindTitleMouse() {
            outNode.find(".imagesTitle li").mouseenter(function () {
                var rightNowQq = parseInt($(this).attr('mynum'));
                outNode.find(".imagesNum").eq(rightNowQq).trigger('click');
            });
            outNode.find(".imagesList").show();
        }



    },
    myTopRolling: function () {
        var n = 0;
        var outNode = $(this);
        var tabNode = outNode.find(".FocusItem");
        var picNum = tabNode.length;
        var todo = true;

        //按照图片个数生成相应按钮
        var imageButton = "<ul class='imagesList'>";
        for (var i = 1; i <= picNum; i++) {
            imageButton = imageButton + "<li class='imagesNum'>" + i + "</li>";
        }
        imageButton = imageButton + "</ul>";
        outNode.prepend(imageButton);
        var btnNode = outNode.find(".imagesNum");
        //设置点击切换
        btnNode.each(function (index) {
            n = index;
            $(this).click(function () {
                if(!todo)
                    return false;
                todo = false;
                tabNode.filter(":visible").fadeOut(200);
                tabNode.eq(n).fadeIn(300, function(){todo = true;});
                btnNode.removeClass("currently");
                $(this).addClass("currently");
            });
        });

        //设置初始化属性
        btnNode.eq(0).trigger('click');
        auto = setInterval(showAuto, 3000);
        outNode.hover(function () { clearInterval(auto) }, function () { auto = setInterval(showAuto, 3000); });
        function showAuto() {
            n = (n >= (picNum - 1)) ? 0 : ++n;
            btnNode.eq(n).trigger('click');
        }
    },
    msnRolling: function () {
        var t = n = count = 0;
        var outNode = $(this);
        var picNum = outNode.find(".FocusItem").size();
        var imageButton = "<ul class='imagesList'>";
        for (var i = 1; i <= picNum; i++) {
            imageButton = imageButton + "<li class='imagesNum'>" + i + "</li>";
        }
        imageButton = imageButton + "</ul>"
        $(this).prepend(imageButton);

        outNode.find(".imagesNum").mouseover(function () {
            var i = $(this).text() - 1;
            n = i;
            if (i >= picNum) return;
            var visibleItem = outNode.find(".FocusItem").filter(":visible");
            visibleItem.hide();
            var currentItem = outNode.find(".FocusItem").eq(i);
            currentItem.show();
            if (currentItem.find('a').length > 0) {
                var a = currentItem.find('a');
                outNode.find('.focustitle').html('<a href="' + a.attr('href') + '" target="_blank">' + a.attr('title') + '</a>');
            } else if (currentItem.find('iframe').length > 0) {
                var iframe = currentItem.find('iframe');
                outNode.find('.focustitle').html('<a href="' + iframe.data('url') + '" target="_blank">' + iframe.data('title') + '</a>');
            }
            if (outNode.find(".FocusItem").filter(":visible").size() == 0) {
                outNode.find(".FocusItem").eq(i).show();
            };
            outNode.find(".imagesNum").removeClass("currently");
            $(this).addClass("currently");
        });

        $(this + ".FocusItem:not(:first-child)").hide();
        $(this + ".imagesNum:first-child").addClass("currently");
        outNode.find(".imagesNum").eq(0).mouseover();
        auto = setInterval(showAuto, 3000);
        outNode.find('.focusPicList').mouseover(function () { clearInterval(auto) });
        outNode.find('.focusPicList').mouseout(function () { auto = setInterval(showAuto, 3000); });
        function showAuto() {
            n = n >= (picNum) ? 0 : ++n;
            outNode.find(".imagesNum").eq(n).mouseover();
        }
    }
});

$(document).ready(function () {
    //选项卡
    $(".weddingBBS h3 span").click(function () {


        $(".weddingBBS").hide();
        $(".weddingBlog").show();
    });


    $(".weddingBlog h3 span").click(function () {

        $(".weddingBlog").hide();
        $(".weddingBBS").show();

    });



    //导航展开
    $(".mainnav_channel .SelectIcon").toggle(function () {

        $(this).parent().addClass("hasChinldOnstate");
    }, function () {

        $(this).parent().removeClass("hasChinldOnstate"); ;
    });

});




jQuery.fn.loadthumb = function (options) {
    options = $.extend({
        src: ""
    }, options);
    var _self = this;
    _self.hide();
    var img = new Image();
    $(img).load(function () {
        _self.attr("src", options.src);
        _self.fadeIn("slow");
    }).attr("src", options.src);  //.atte("src",options.src)要放在load后面，
    return _self;
}

$(function () {
    var i = 4;  //已知显示的<a>元素的个数
    var m = 4;  //用于计算的变量
    var $content = $("#slideshowbox .scrollableDiv");
    var count = $content.find("a").length; //总共的<a>元素的个数
    //下一张
    $(".next").live("click", function () {
        var $scrollableDiv = $(this).siblings(".items").find(".scrollableDiv");
        if (!$scrollableDiv.is(":animated")) {  //判断元素是否正处于动画，如果不处于动画状态，则追加动画。
            if (m < count) {  //判断 i 是否小于总的个数
                m++;
                $scrollableDiv.animate({ left: "-=121px" }, 600);
            }
        }
        return false;
    });
    //上一张
    $(".prev").live("click", function () {
        var $scrollableDiv = $(this).siblings(".items").find(".scrollableDiv");
        if (!$scrollableDiv.is(":animated")) {
            if (m > i) { //判断 i 是否小于总的个数
                m--;
                $scrollableDiv.animate({ left: "+=121px" }, 600);
            }
        }
        return false;
    });

    $(".scrollableDiv a").live("click", function () {
        var src = $(this).find("img").attr("imgb");
        $(this).parents("#slideshowbox").find(".myImgs").loadthumb({ src: src });
        $(this).parents("#slideshowbox").siblings("#slideshowText").html($(this).find("img").attr("desc"));
        $(this).addClass("active").siblings().removeClass("active");
        if (m - parseInt($(this).find("img").attr("id")) < 2) {
            $(".next").trigger("click");
        } else {
            $(".prev").trigger("click");
        }
        return false;
    });
    $(".scrollableDiv a:nth-child(1)").trigger("click");
});

// bookmarkshare
function ShowShareDialog() {
    var _linkTitle = document.title;
    var _linkUrl = window.location.href;
    var _openUrl = "iframe:/Sites/IJie/SendLinksTo.aspx?linkTitle=" + escape(_linkTitle) + "&linkUrl=" + _linkUrl;
    dialog('分享', _openUrl, '450px', '550px', 'iframe');
}

// subscribe email
function SaveNewsletter() {
    if ($("#hidSubmitEmail").val() == "1") {
        return;
    }
    var exp = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!exp.test($("#txtEmail").val())) {
        $("#txtEmail").val('请提供有效的电子邮件地址');
    } else {
        $("#hidSubmitEmail").val("1");
        $.ajax({
            type: "GET",
            url: "/?device=json&action=AddNewsLetter",
            data: "email=" + $("#txtEmail").val(),
            dataType: "text",
            success: function (msg) {
                alert(msg);
            },
            complete: function () {
                $("#hidSubmitEmail").val("0");
            }
        });
    }
}
// fun poll
function SubmitSelect(PollServiceUrl, pollId, answerListIds, answerSelectionIds) {
    var voted = getCookie("voted");
    if (voted) {
        alert("您已投过票了");
        return;
    }
    //    if ($("#hidFunPollFlag").val() != "true") {
    //        return;
    //    }
    //    $("#hidFunPollFlag").val("false");
    $("#floatBox").find(".vs-box-big").eq(0).show();
    $("#floatBox").find(".vs-box-big").eq(1).hide();
    var url = PollServiceUrl + "/SavePollResult/" + pollId + "/?answerListIds=" + answerListIds + "&answerSelectionIds=" + answerSelectionIds + "&jsonp=?";
    $.getJSON(url,
        function (data) {
            /*get the poll result data*/
            $("#floatBox").find(".vs-box-big").eq(0).show();
            $("#floatBox").find(".vs-box-big").eq(1).hide();
            var pollResults = eval(data);
            var answerArray = answerListIds.split(",");
            for (irene = 0; irene < pollResults.length; irene++) {

                sitecoreAnswerID = pollResults[irene].SitecoreAnswerID;

                for (var i = 0; i < answerArray.length; i++) {
                    if (sitecoreAnswerID == answerArray[i]) {
                        $("#" + sitecoreAnswerID).html("得票数：" + pollResults[irene].VoteCount + "（" + pollResults[irene].VotePercentage + "%）");
                        $("#" + sitecoreAnswerID).show();
                        $("#floatBox").find("#" + sitecoreAnswerID).html("得票数：" + pollResults[irene].VoteCount + "（" + pollResults[irene].VotePercentage + "%）");
                        $("#floatBox").find("#" + sitecoreAnswerID).show();
                    }
                }
            }
            $("#floatBox").find(".vs-box-big").eq(0).hide();
            $("#floatBox").find(".vs-box-big").eq(1).show();
        }
    );
}

function ShowResult(PollServiceUrl, pollId, answerListIds) {

    dialog('FunPolls', 'id:div_LeeDialog', '630px', '407px', 'id');
    $("#floatBox").find(".vs-box-big").eq(0).show();
    $("#floatBox").find(".vs-box-big").eq(1).hide();

    var url = PollServiceUrl + "/GetPollResults/" + pollId + "/?&jsonp=?";

    $.getJSON(url,
        function (data) {
            /*get the poll result data*/
            var pollResults = eval(data);
            var answerArray = answerListIds.split(",");
            for (irene = 0; irene < pollResults.length; irene++) {

                sitecoreAnswerID = pollResults[irene].SitecoreAnswerID;

                for (var i = 0; i < answerArray.length; i++) {
                    if (sitecoreAnswerID == answerArray[i]) {
                        $("#" + sitecoreAnswerID).html("得票数：" + pollResults[irene].VoteCount + "（" + pollResults[irene].VotePercentage + "%）");
                        $("#" + sitecoreAnswerID).show();
                        $("#floatBox").find("#" + sitecoreAnswerID).html("得票数：" + pollResults[irene].VoteCount + "（" + pollResults[irene].VotePercentage + "%）");
                        $("#floatBox").find("#" + sitecoreAnswerID).show();
                    }
                }
            }
            $("#floatBox").find(".vs-box-big").eq(0).hide();
            $("#floatBox").find(".vs-box-big").eq(1).show();
        });
}

// quiz
function Pre_QZ_onClick() {
    var max = $("#imageflowquizzes").find("img").length;
    var curreid = $("#imageflowquizzes").find("#hidCurrentId").val();
    $("#imageflowquizzes").find("img").eq(curreid).hide();
    curreid--;
    if (curreid < 0) {
        curreid = max - 1;
    }
    $("#imageflowquizzes").find("#hidCurrentId").val(curreid);
    $("#imageflowquizzes").find("img").eq(curreid).show();
}
function Next_QZ_onClick() {
    var max = $("#imageflowquizzes").find("img").length;
    var curreid = $("#imageflowquizzes").find("#hidCurrentId").val();
    $("#imageflowquizzes").find("img").eq(curreid).hide();
    curreid++;
    if (curreid >= max) {
        curreid = 0;
    }
    $("#imageflowquizzes").find("#hidCurrentId").val(curreid);
    $("#imageflowquizzes").find("img").eq(curreid).show();
}

//snow
(function (a) { a.snowfall = function (c, b) { function o(e, j, p, q, r) { this.id = r; this.x = e; this.y = j; this.size = p; this.speed = q; this.step = 0; this.stepSize = d(1, 10) / 100; e = a(document.createElement("div")).attr({ "class": "snowfall-flakes", id: "flake-" + this.id }).css({ width: this.size, height: this.size, background: b.flakeColor, position: "absolute", top: this.y, left: this.x, fontSize: 0, zIndex: b.flakeIndex }); if (a(c).get(0).tagName === a(document).get(0).tagName) { a("body").append(e); c = a("body") } else a(c).append(e); this.element = document.getElementById("flake-" + this.id); this.update = function () { this.y += this.speed; this.y > k - (this.size + 6) && this.reset(); this.element.style.top = this.y + "px"; this.element.style.left = this.x + "px"; this.step += this.stepSize; this.x += Math.cos(this.step); if (this.x > i - f || this.x < f) this.reset() }; this.reset = function () { this.y = 0; this.x = d(f, i - f); this.stepSize = d(1, 10) / 100; this.size = d(b.minSize * 100, b.maxSize * 100) / 100; this.speed = d(b.minSpeed, b.maxSpeed) } } function l() { for (g = 0; g < h.length; g += 1) h[g].update(); m = setTimeout(function () { l() }, 30) } b = a.extend({ flakeCount: 35, flakeColor: "#fff", flakeIndex: 999999, minSize: 1, maxSize: 3, minSpeed: 2, maxSpeed: 3, round: false, shadow: false }, b); var d = function (e, j) { return Math.round(e + Math.random() * (j - e)) }; a(c).data("snowfall", this); var h = [], n = 0, g = 0, k = a(c).height(), i = a(c).width(), f = 0, m = 0; if (a(c).get(0).tagName === a(document).get(0).tagName) f = 25; a(window).bind("resize", function () { k = a(c).height(); i = a(c).width() }); for (g = 0; g < b.flakeCount; g += 1) { n = h.length; h.push(new o(d(f, i - f), d(0, k), d(b.minSize * 100, b.maxSize * 100) / 100, d(b.minSpeed, b.maxSpeed), n)) } b.round && a(".snowfall-flakes").css({ "-moz-border-radius": b.maxSize, "-webkit-border-radius": b.maxSize, "border-radius": b.maxSize }); b.shadow && a(".snowfall-flakes").css({ "-moz-box-shadow": "1px 1px 1px #555", "-webkit-box-shadow": "1px 1px 1px #555", "box-shadow": "1px 1px 1px #555" }); l(); this.clear = function () { a(c).children(".snowfall-flakes").remove(); h = []; clearTimeout(m) } }; a.fn.snowfall = function (c) { if (typeof c == "object" || c == undefined) return this.each(function () { new a.snowfall(this, c) }); else if (typeof c == "string") return this.each(function () { var b = a(this).data("snowfall"); b && b.clear() }) } })(jQuery);

//SeoLink
function getCfpSeoLink() {
    var url = "http://www.cfp.cn";
    $("#seoLinkCFP").attr("href", url);

}
